package com.banshuibao.bsb_android.util;

import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;

import java.text.DecimalFormat;

/**
 * Created by wangpan on 2018/3/21.
 */

public class PriceUtil {

   static DecimalFormat decimalFormat =new DecimalFormat("0.00");

    /**
     * 保留两们小数，且小数点后两位字体小于整数部分
     * @return
     */
    public static SpannableString FormatPrice(double price){
        String content = "";
        content = decimalFormat.format(price);
        SpannableString spanString = new SpannableString(content);
        AbsoluteSizeSpan span = new AbsoluteSizeSpan(22);
        spanString.setSpan(span, content.length()-2, content.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        return spanString;
    }

    /**
     * 保留两们小数
     */
    public static String FormatDecimal(double price){
        String content = "";
        content = decimalFormat.format(price);
        return content;
    }
}
